﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBUtility;
using List;
using DevExpress.XtraCharts;

namespace HXSH5._0
{
    public partial class Chart2 : Form
    {
        public Chart2()
        {
            InitializeComponent();
        }

        private void Chart2_Load(object sender, EventArgs e)
        {
            BreakList.Brakelist(LoginForm.user.Trim(), comboBox2);
            string sql = "select distinct CdPart from cd_info where BrakeId='" + comboBox2.Text.Trim() + "'";
            DataSet ds = DbHelperSQL.Query(sql);
            comboBox1.DataSource = ds.Tables[0];
            comboBox1.DisplayMember = "CdPart";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string checkedText = string.Empty;
            if (checkedListBox1.CheckedItems.Count == 1)
            {
                for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
                {
                    DataRowView dv = ((DataRowView)checkedListBox1.CheckedItems[i]);
                    checkedText += dv["CdId"].ToString() + " ";
                }
                textBox1.Text = checkedText;
                string SQL = "select CdId,Ljwyl,ObserDate from LJWYL WHERE BreakName='" + comboBox2.Text.Trim() + "' and CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(0, 3) + "'";
                DataTable dt = DbHelperSQL.GetDataTable(SQL);
                chartControl1.Titles.Clear();
                ChartTitle _title = new ChartTitle();
                _title.Text = "垂直位移量横断面过程线" + "(" + comboBox1.Text.Trim() + ")";
                chartControl1.Titles.Add(_title);
                chartControl1.Series.Clear();
                Series S1 = new Series();
                S1.ArgumentScaleType = ScaleType.DateTime;//设置X轴类型为日期型
                chartControl1.DataSource = dt;
                chartControl1.Series.Add(S1);
                chartControl1.SeriesDataMember = "CdId";
                chartControl1.SeriesTemplate.ArgumentDataMember = "ObserDate";
                chartControl1.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Ljwyl" });

                //((LineSeriesView)S1.View).LineStyle.DashStyle = DashStyle.DashDot; //S1以虚线显示
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "累计位移量mm";
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visible = true;
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Font = new Font("宋体", 15);
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.TextColor = System.Drawing.Color.Black;

            }

            else if (checkedListBox1.CheckedItems.Count == 2)
            {
                for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
                {
                    DataRowView dv = ((DataRowView)checkedListBox1.CheckedItems[i]);
                    checkedText += dv["CdId"].ToString() + " ";
                }
                textBox1.Text = checkedText;
                //string SQL = "select CdId,Ljwyl,ObserDate from Ljwy WHERE CdPosition='底板'and (CdId='1-1'or CdId='1-2')";
                string SQL = "select CdId,Ljwyl,ObserDate from Ljwy WHERE BreakName='" + comboBox2.Text.Trim() + "' and CdPosition='" + comboBox1.Text.Trim() + "' and (CdId='" + (textBox1.Text).Substring(0, 3) + "'or CdId='" + (textBox1.Text).Substring(4, 3) + "')";
                DataTable dt = DbHelperSQL.GetDataTable(SQL);
                chartControl1.Titles.Clear();
                ChartTitle _title = new ChartTitle();
                _title.Text = "垂直位移量横断面过程线" + "(" + comboBox1.Text.Trim() + ")";
                chartControl1.Titles.Add(_title);
                chartControl1.Series.Clear();
                Series S1 = new Series();
                Series S2 = new Series();
                S1.ArgumentScaleType = ScaleType.DateTime;//设置X轴类型为日期型
                // S2.ArgumentScaleType = ScaleType.DateTime;
                chartControl1.DataSource = dt;
                chartControl1.Series.Add(S1);
                chartControl1.Series.Add(S2);
                chartControl1.SeriesDataMember = "CdId";
                chartControl1.SeriesTemplate.ArgumentDataMember = "ObserDate";
                chartControl1.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Ljwyl" });
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "累计位移量mm";
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visible = true;
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Font = new Font("宋体", 15);
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.TextColor = System.Drawing.Color.Black;
            }
            else if (checkedListBox1.CheckedItems.Count == 3)
            {
                for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
                {
                    DataRowView dv = ((DataRowView)checkedListBox1.CheckedItems[i]);
                    checkedText += dv["CdId"].ToString() + " ";
                }
                textBox1.Text = checkedText;
                string SQL = "select CdId,Ljwyl,ObserDate from Ljwy WHERE BreakName='" + comboBox2.Text.Trim() + "' and CdPosition='" + comboBox1.Text.Trim() + "' and (CdId='" + (textBox1.Text).Substring(0, 3) + "'or CdId='" + (textBox1.Text).Substring(4, 3) + "'or  CdId='" + (textBox1.Text).Substring(8, 3) + "')";
                //string SQL = "select CdId,Ljwyl,ObserDate from Ljwy WHERE CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(0, 3) + "'union select CdId,Ljwyl ,ObserDate from Ljwy WHERE CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(4, 3) + "'union select CdId,Ljwyl ,ObserDate from Ljwy WHERE CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(8, 3) + "'";
                DataTable dt = DbHelperSQL.GetDataTable(SQL);
                chartControl1.Titles.Clear();
                ChartTitle _title = new ChartTitle();
                _title.Text = "垂直位移量横断面过程线" + "(" + comboBox1.Text.Trim() + ")";
                chartControl1.Titles.Add(_title);
                chartControl1.Series.Clear();
                Series S1 = new Series();
                Series S2 = new Series();
                Series S3 = new Series();

                S1.ArgumentScaleType = ScaleType.DateTime;//设置X轴类型为日期型
                //S2.ArgumentScaleType = ScaleType.DateTime;
                //S3.ArgumentScaleType = ScaleType.DateTime;
                chartControl1.DataSource = dt;
                chartControl1.Series.Add(S1);
                chartControl1.Series.Add(S2);
                chartControl1.Series.Add(S3);
                chartControl1.SeriesDataMember = "CdId";
                chartControl1.SeriesTemplate.ArgumentDataMember = "ObserDate";
                chartControl1.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Ljwyl" });
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "累计位移量mm";
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visible = true;
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Font = new Font("宋体", 15);
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.TextColor = System.Drawing.Color.Black;
            }
            else if (checkedListBox1.CheckedItems.Count == 4)
            {
                for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
                {
                    DataRowView dv = ((DataRowView)checkedListBox1.CheckedItems[i]);
                    checkedText += dv["CdId"].ToString() + " ";
                }
                textBox1.Text = checkedText;
                string SQL = "select CdId,Ljwyl,ObserDate from Ljwy WHERE BreakName='" + comboBox2.Text.Trim() + "' and CdPosition='" + comboBox1.Text.Trim() + "' and (CdId='" + (textBox1.Text).Substring(0, 3) + "'or CdId='" + (textBox1.Text).Substring(4, 3) + "'or  CdId='" + (textBox1.Text).Substring(8, 3) + "'or CdId='" + (textBox1.Text).Substring(12, 3) + "')";
                //string SQL = "select CdId,Ljwyl,ObserDate from Ljwy WHERE CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(0, 3) + "'union select CdId,Ljwyl ,ObserDate from Ljwy WHERE CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(4, 3) + "'union select CdId,Ljwyl ,ObserDate from Ljwy WHERE CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(8, 3) + "'union select CdId,Ljwyl ,ObserDate from Ljwy WHERE CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(12, 3) + "'union select CdId,Ljwyl ,ObserDate from Ljwy WHERE CdPosition='" + comboBox1.Text.Trim() + "' and CdId='" + (textBox1.Text).Substring(8, 3) +"'";
                DataTable dt = DbHelperSQL.GetDataTable(SQL);
                chartControl1.Titles.Clear();
                ChartTitle _title = new ChartTitle();
                _title.Text = "垂直位移量横断面过程线" + "(" + comboBox1.Text.Trim() + ")";
                chartControl1.Titles.Add(_title);
                chartControl1.Series.Clear();
                Series S1 = new Series();
                Series S2 = new Series();
                Series S3 = new Series();
                Series S4 = new Series();
                S1.ArgumentScaleType = ScaleType.DateTime;//设置X轴类型为日期型
                chartControl1.DataSource = dt;
                chartControl1.Series.Add(S1);
                chartControl1.Series.Add(S2);
                chartControl1.Series.Add(S3);
                chartControl1.Series.Add(S4);
                chartControl1.SeriesDataMember = "CdId";
                chartControl1.SeriesTemplate.ArgumentDataMember = "ObserDate";
                chartControl1.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Ljwyl" });
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "累计位移量mm";
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visible = true;
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.Font = new Font("宋体", 15);
                ((XYDiagram)chartControl1.Diagram).AxisY.Title.TextColor = System.Drawing.Color.Black;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFD = new SaveFileDialog();
            saveFD.Filter = "Image files(*.jpeg,*.gif)|*.jpeg;*.gif";
            saveFD.CheckFileExists = false;
            saveFD.CheckPathExists = false;
            saveFD.FilterIndex = 0;
            saveFD.RestoreDirectory = true;
            saveFD.CreatePrompt = true;
            saveFD.Title = "保存为image文件";
            if (saveFD.ShowDialog() == DialogResult.OK)
            {
                chartControl1.ExportToImage(saveFD.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            string sql = "select CdId from cd_info where BrakeId='" + comboBox2.Text.Trim() + "'and CdPart='" + comboBox1.Text.Trim() + "'";
            DataTable dt = DbHelperSQL.GetDataTable(sql);
            checkedListBox1.DataSource = dt;
            checkedListBox1.DisplayMember = "CdId";
        }
    }
}
